import Layout from '../layout/Layout.vue'
import { createRouter, createWebHistory } from "vue-router";




export const constantRoutes = [
    { path: '/Login', name: 'Login', component: () => import("@/views/Login") },
    {
        path: '/Layout', name: 'Layout', component: Layout, children: [
            { path: '/home', name: '主页', component: () => import("@/views/Home") },
            { path: '/stuInfo', name: '学生信息', component: () => import("@/views/system/StuInfo") },
            { path: '/teacherInfo', name: '辅导员信息', component: () => import("@/views/system/TeacherInfo") },

            { path: '/dormManagerInfo', name: 'DormManagerInfo', component: () => import("@/views/system/DormManagerInfo") },
            { path: '/buildingInfo', name: '楼宇信息', component: () => import("@/views/BuildingInfo") },
            { path: '/roomInfo', name: '房间信息', component: () => import("@/views/stu/RoomInfo") },
            { path: '/noticeInfo', name: '公告信息', component: () => import("@/views/NoticeInfo") },
            { path: '/repairInfo', name: '报修信息', component: () => import("@/views/RepairInfo") },
            { path: '/adjustRoomInfo', name: '调宿申请', component: () => import("@/views/AdjustRoomInfo") },

            { path: '/visitorInfo', name: '学生访客申请', component: () => import("@/views/stu/VisitorInfo") },
            { path: '/teavisitorInfo', name: '访客审批', component: () => import("@/views/teacher/TeaVisitorInfo") },
            { path: '/tesLeave', name: '请假申请审批', component: () => import("@/views/teacher/TesLeave") },
            { path: '/stuLeave', name: '请假申请', component: () => import("@/views/stu/StuLeave") },


            { path: '/WaterInfo', name: '水费管理', component: () => import("@/views/dorm/WaterInfo") },
            { path: '/StuWaterInfo', name: '电费管理', component: () => import("@/views/stu/StuWaterInfo") },
            { path: '/payhistory', name: '水电费缴纳记录', component: () => import("@/views/stu/payhistory") },
            { path: '/waterEcharts', name: '水电费统计', component: () => import("@/views/stu/waterEcharts") },


            { path: '/CheckInfo', name: '卫生检查', component: () => import("@/views/dorm/CheckInfo") },
            { path: '/CheckAvg', name: '卫生分数排名', component: () => import("@/views/dorm/CheckAvg") },

            { path: '/Checknum', name: '每日卫生分数统计', component: () => import("@/views/stu/Checknum") },

            { path: '/applyAbsentRecord', name: '管理缺寝记录', component: () => import("@/views/dorm/ApplyAbsentRecord") },
            { path: '/sysRoleList', name: '角色管理', component: () => import("@/views/system/sysRoleList") },
            { path: '/sysMenuList', name: '权限管理', component: () => import("@/views/system/sysMenuList") },
            //
            { path: '/myRoomInfo', name: '我的宿舍', component: () => import("@/views/stu/MyRoomInfo") },
            { path: '/applyRepairInfo', name: '报修申请', component: () => import("@/views/stu/ApplyRepairInfo") },
            { path: '/applyChangeRoom', name: '申请调宿', component: () => import("@/views/stu/ApplyChangeRoom") },

            { path: '/absentRecord', name: '学生缺寝记录', component: () => import("@/views/stu/AbsentRecord") },
            { path: '/stuChangeRoom', name: '学生报修申请', component: () => import("@/views/stu/StuChangeRoom") },
            { path: '/lm', name: '聊天', component: () => import("@/views/lm") },

            { path: '/selfInfo', name: '个人信息', component: () => import("@/views/SelfInfo") },
        ]
    },
    // {
    //     path: '/system',
    //     component: Layout,
    //     alwaysShow: true,
    //     name: '系统管理',
    //     meta: { title: '系统管理', icon: 'system' },
    //     children: [
    //         {
    //             path: 'sysRoleList',
    //             name: '角色管理',
    //             component: () => import("@/views/system/sysRoleList"),
    //             meta: { title: '角色管理', icon: 'role' }
    //         },
    //         {
    //             path: 'sysMenuList',
    //             name: '权限管理',
    //             component: () => import("@/views/system/sysMenuList"),
    //             meta: { title: '权限管理', icon: 'menu' }
    //         }
    //     ]
    // },

]
const router = createRouter({
    routes: constantRoutes,
    history: createWebHistory(process.env.BASE_URL)
})
//路由守卫
router.beforeEach((to, from, next) => {
    //to 要访问的路径
    //from 代表从哪个路径跳转而来
    // next 是函数，表示放行
    // next() 放行
    // next('/*') 强制跳转
    const user = window.sessionStorage.getItem('user')
    if (to.path === '/Login') {
        return next();
    }
    if (!user) {
        return next('/Login')
    }
    if (to.path === '/' && user) {
        return next('/home')
    }
    next()
})

export default router
